import {LOGIN, GET_USER, ROUTES} from '@/services/api';
import {request,req, METHOD, removeAuthorization, getAuthorization} from '@/utils/request';
//import Login from "../pages/login/Login";


/**
 * 登录服务
 * @param name 账户名
 * @param password 账户密码
 * @returns {Promise<AxiosResponse<T>>}
 */
/*export async function login(name, password) {
  return request(LOGIN, METHOD.POST, {
    name: name,
    password: password
  })
}*/

export const login = async (name, password) =>{
    return await getAuthorization(LOGIN,{username:name,password:password});
}

export const getUser = async () =>{
    return await req(GET_USER);
}

export async function getRoutesConfig() {
  return request(ROUTES, METHOD.GET)
}


/**
 * 退出登录
 */
export function logout() {
  localStorage.removeItem(process.env.VUE_APP_ROUTES_KEY)
  localStorage.removeItem(process.env.VUE_APP_PERMISSIONS_KEY)
  localStorage.removeItem(process.env.VUE_APP_ROLES_KEY)
  removeAuthorization()
}
export default {
  login,
  getUser,
  logout,
  getRoutesConfig
}
